﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VietImage.Models;
using System.Web.Mvc;

namespace VietImage.Helpers
{
    public class ControllerHelper
    {
        public static void GetLanguage(ViewDataDictionary ViewData, HttpRequestBase Request, HttpResponseBase Response)
        {
            //HttpCookie languageCookie = Request.Cookies["Language"];
            HttpCookie languageCookie = null;
            if (languageCookie == null)
            {
                languageCookie = new HttpCookie("Language");
                languageCookie.Value = "2";
            }
            languageCookie.Expires = DateTime.Now.AddMonths(1);
            //Response.SetCookie(languageCookie);
            ViewData["Language"] = int.Parse(languageCookie.Value);
        }

        public static String GetErrorResult(List<ErrorItem> errorlist)
        {
            String result = "";
            if (errorlist != null && errorlist.Count > 0)
            {
                result = "Error:\n";
                foreach (ErrorItem error in errorlist)
                {
                    result += "- " + error + "\n";
                }
            }
            else
            {
                result = "Success!";
            }
            return result;
        }

        public static bool HasFile(HttpPostedFileBase file)
        {
            return (file != null && file.ContentLength > 0) ? true : false;
        }

    }
}